import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:star_unbounded/model/clipboard_data.dart';
class UploadCard extends StatefulWidget {
  const UploadCard({super.key}) ;
  @override
  State<StatefulWidget> createState()  =>_UploadCard();
}

class _UploadCard extends State<UploadCard>{
  @override
  Widget build(BuildContext context) {
    ClipboardDataType type = context.select((ClipboardData r)=>r.type);
    String? text = context.select((ClipboardData r)=>r.text) ;
    Uint8List? img = context.select((ClipboardData r)=>r.img);
    if(type == ClipboardDataType.nil)return Container();
    return Column(
      children: [
         Card(
          child: Container(
            width: 320,
            padding: const EdgeInsets.fromLTRB(10, 10, 10, 10),
            child: Builder(
              builder: (context) {
                if(type == ClipboardDataType.text){
                  return  Column(
                    children: [
                       Text(text!)
                    ],
                  );
                }
                if(type == ClipboardDataType.image){
                  return Column(children: [
                      Image.memory(img!,width: 200,)
                  ],);
                }
                return Container();
              }
            ),
          ),
        ),
        const SizedBox(height: 14,),
        ElevatedButton.icon(onPressed: (){}, label: const Text("同步数据"),icon: const Icon(Icons.upload_sharp),)
      ],
    );

  }

}